package com.train.member.Controller;

import com.train.common.resp.CommonResp;
import com.train.member.domain.Member;
import com.train.member.req.MemberLoginReq;
import com.train.member.req.MemberRegisterReq;
import com.train.member.resp.MemberLoginResp;
import com.train.member.service.MemberService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
public class MemberController {
    @Resource
    private MemberService memberService;

    @PostMapping("/send-code")
    public CommonResp<String> sendCode(@Valid @RequestBody MemberRegisterReq memberRegisterReq){
        //后面对接了发送短信的接口，直接返回生成的随机数然后发送短信到用户手机上
        return new CommonResp<>("8888");
    }

    @PostMapping("/register")
    public CommonResp<Long> Register(@Valid @RequestBody MemberRegisterReq memberRegisterReq){
        long register = memberService.Register(memberRegisterReq);
        return new CommonResp<>(register);
    }

    @PostMapping("/login")
    public CommonResp<MemberLoginResp> Login(@Valid @RequestBody MemberLoginReq memberLoginReq){
        MemberLoginResp memberLoginResp = memberService.login(memberLoginReq);
        return new CommonResp<>(memberLoginResp);
    }

}
